#include<bits/stdc++.h>
using namespace std;

int n, m;
int dir[8][2] = {{0,  1},
                 {1,  0},
                 {0,  -1},
                 {-1, 0},
                 {1,  1},
                 {-1, 1},
                 {1,  -1},
                 {-1, -1}};
char arr[105][105];
int ans[105][105];

void func(int x, int y);

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            cin >> arr[i][j];

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            func(i, j);

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (ans[i][j] == -1)
                cout << '*';
            else
                cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}

void func(int x, int y) {
    if (arr[x][y] == '*')
        ans[x][y] = -1;
    else
        for (auto &k: dir) {
            int dx = x + k[0];
            int dy = y + k[1];
            if (arr[dx][dy] == '*')
                ++ans[x][y];
        }
}